<?php


namespace app\admin\controller;


use think\Db;
use think\facade\Request;

class ApplyManageController extends BaseController
{
    #添加上传表
    public function add()
    {
        $file = request()->file('image');
        // 移动到框架应用根目录/uploads/ 目录下
        $info = $file->move( '../public/uploads/manageInfo');
        if($info){
            // 成功上传后 获取上传信息
            // 输出 jpg
            echo $info->getExtension();
            // 输出 20160820/42a79759f284b767dfcb2a0197904287.jpg
            echo $info->getSaveName();
            // 输出 42a79759f284b767dfcb2a0197904287.jpg
            echo $info->getFilename();
        }else{
            // 上传失败获取错误信息
            echo $file->getError();
        }
    }


    #删除信息
    public function deleteinfo()
    {
        $id = intval($_GET['id']);
        $data = Db::name('download_info')->where('id',$id)->delete();
        if ($data == 1 && $id!=0){
            echo $data.'删除失败！';
            header("Refresh:1;url=/ShirneCMS/src/public/admin/apply_manage/index.html");
        }
        else{
            echo $data.'删除失败！';
            header("Refresh:1;url=/tp5.1/public/Upfile_Manage/select");
        }
    }

    #传递需要更新的信息
    public function edit()
    {
        $id = intval($_GET['id']);

        $data3 = Db::name('download_info')->where('id',$id)->find();
        $this->assign('data3',$data3);
        return $this->fetch();
    }

    //更新信息
    public function updateinfo()
    {
        $id = Request::post('id1');
        $title = Request::post('title1');
        $describle = Request::post('describle1');
        $updata = [
            'id' => $id,
            'title' => $title,
            'describle' => $describle,
        ];

            $data = Db::name('download_info')->where($id)->update($updata);
            /*if ($data == 1 && $id != null)
            {
                echo $data.'更改成功';
                header("Refresh:1;url=/ShirneCMS/src/public/admin/apply_manage/index.html");
            }
            else{
                echo $data.'更改失败,请不要更改id';
                header("Refresh:2;url=/ShirneCMS/src/public/admin/apply_manage/index.html");
            }*/
    }

    //查询所有的信息
    public function index()
    {
        $data = Db::name('download_info')->select();
        $this->assign('data2',$data);
        return $this->fetch();
    }

}